
#import "PURecordCell.h"

@implementation PURecordCell

- (NSMutableArray<UIImageView *> *)imageViewArrM {
    if (_imageViewArrM == nil) {
        _imageViewArrM = [NSMutableArray array];
    }
    return _imageViewArrM;
}
-(UIView*)imagebgView{
    if (!_imagebgView) {
        _imagebgView=[[UIView alloc]init];
//        _headbgView.backgroundColor=[UIColor colorWithHex:0xFAFCFF];
    }
    return _imagebgView;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initViews];
    }
    return  self;
}
-(void)initViews{

//    CGFloat width=_window_width;
//    self.bgView=[[UIView alloc]init];
//    self.bgView.frame=CGRectMake(12*KWidthScale, 6*KWidthScale, width-12*KWidthScale*2, 68*KWidthScale);
//    self.bgView.backgroundColor=[UIColor whiteColor];
//    self.bgView.layer.cornerRadius = 10;
//    self.bgView.layer.masksToBounds=YES;
//    [self.contentView addSubview:self.bgView];
    
//    self.touImage=[[UIImageView alloc]init];
//    self.touImage.contentMode=UIViewContentModeScaleAspectFill;
//    self.touImage.layer.borderColor = [UIColor whiteColor].CGColor;
//    self.touImage.layer.borderWidth = 1.0;
//    self.touImage.layer.masksToBounds=YES;
//    self.touImage.backgroundColor=[UIColor colorWithHex:0xDCDCDC];
//    [self.contentView addSubview:self.touImage];
    
//    self.nameLab = [[UILabel alloc] init];
//    self.nameLab.font=[UIFont boldSystemFontOfSize:17];
//    self.nameLab.textColor = [UIColor blackColor];
//    [self.contentView addSubview:self.nameLab];
    
//    self.LVImage=[[UIImageView alloc]init];
//    self.LVImage.image=[UIImage imageNamed:@"huaLV1_不带称号"];
//    [self.contentView addSubview:self.LVImage];
    
    self.neirongLab = [[UILabel alloc] init];
    self.neirongLab.text=@"内容";
    self.neirongLab.font=[UIFont systemFontOfSize:15];
    self.neirongLab.textColor = [UIColor blackColor];
    self.neirongLab.numberOfLines=0;
    [self.contentView addSubview:self.neirongLab];
    
    self.timeLab = [[UILabel alloc] init];
    self.timeLab.text=@"时间";
    self.timeLab.font=[UIFont systemFontOfSize:10];
    self.timeLab.textColor = [UIColor lightGrayColor];
    self.timeLab.textAlignment=NSTextAlignmentRight;
    [self.contentView addSubview:self.timeLab];
    
    self.statusLab = [[UILabel alloc] init];
    self.statusLab.text=@"审核中";
    self.statusLab.font=[UIFont systemFontOfSize:12];
    self.statusLab.textColor = [UIColor colorWithHex:0xFF729A];
    self.statusLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:self.statusLab];
    
    self.xianView=[[UIView alloc]init];
    self.xianView.backgroundColor=[UIColor colorWithHex:0xF3F3F3];
    self.xianView.alpha=0.5;
    [self.contentView addSubview:self.xianView];
    
//    self.zanBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//    [self.zanBtn setImage:[UIImage imageNamed:@"XL_ZAN"] forState:UIControlStateNormal];//XL_ZAN
//    [self.zanBtn setTitleColor:[UIColor colorWithHex:0xFF729A] forState:UIControlStateNormal];
//    [self.zanBtn addTarget:self action:@selector(zanAction) forControlEvents:UIControlEventTouchUpInside];
//    self.zanBtn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
//    self.zanBtn.titleLabel.font = [UIFont systemFontOfSize:13];
//    [self.zanBtn setTitle:@" 喜欢" forState:UIControlStateNormal];
//    [self.contentView addSubview:self.zanBtn];
//
//
//    self.qgBtn =[UIButton buttonWithType:UIButtonTypeCustom];
//    [self.qgBtn setImage:[UIImage imageNamed:@"XL_QG"] forState:UIControlStateNormal];
//    [self.qgBtn setTitleColor:[UIColor colorWithHex:0xFF729A] forState:UIControlStateNormal];
//    [self.qgBtn addTarget:self action:@selector(zanAction) forControlEvents:UIControlEventTouchUpInside];
//    self.qgBtn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
//    self.qgBtn.titleLabel.font = [UIFont systemFontOfSize:13];
//    [self.contentView addSubview:self.qgBtn];
//    [self.qgBtn setTitle:@" 求购" forState:UIControlStateNormal];

}

//计算有行距的文本的文本高度
-(CGFloat)getSpaceLabelHeight:(NSString *)str withAttrDict:(NSMutableDictionary *)dict withWidth:(CGFloat)width {
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return size.height;
}
-(void)setModel:(PUModel *)model
{
    _model=model;
    
    //设置行距，并根据文本计算高度
    ////// ////// ////// ////// ////// //////
    //富文本属性
    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
    //基本属性设置
    //字体颜色
    textDict[NSForegroundColorAttributeName] = [UIColor blackColor];
    //字号大小
    textDict[NSFontAttributeName] = [UIFont systemFontOfSize:15.0];
    //段落样式
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //行间距
    paraStyle.lineSpacing = 3.0;
    //首行文本缩进
//  paraStyle.firstLineHeadIndent = 20.0;
    //使用
    //文本段落样式
    textDict[NSParagraphStyleAttributeName] = paraStyle;
    //赋值
    self.neirongLab.attributedText = [[NSAttributedString alloc] initWithString:model.flowers_describe attributes:textDict];
    
    self.timeLab.text=model.flowers_buyTime;
    
//    if (model.is_praise == 0) {
//        [self.zanBtn setImage:[UIImage imageNamed:@"DTDZ_N"] forState:UIControlStateNormal];
//        [self.zanBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    }else{
//        [self.zanBtn setImage:[UIImage imageNamed:@"DTDZ_S"] forState:UIControlStateNormal];
//        [self.zanBtn setTitleColor:[UIColor colorWithHex:0xFF729A] forState:UIControlStateNormal];
//    }
//    [self.zanBtn setTitle:[NSString stringWithFormat:@" %ld", (long)model.praise_num] forState:UIControlStateNormal];
    
//    self.touImage.frame=CGRectMake(12*KWidthScale, 12*KWidthScale, 48*KWidthScale, 48*KWidthScale);
//    self.touImage.layer.cornerRadius = self.touImage.frame.size.height/2;
//    CGSize size1 = [model.username sizeWithAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
//    CGFloat width1 = ceil(size1.width);
//    self.nameLab.frame=CGRectMake(self.touImage.frame.origin.x+self.touImage.frame.size.width+12*KWidthScale, 14*KWidthScale, width1, 22*KWidthScale);
//    self.LVImage.frame=CGRectMake(self.nameLab.frame.origin.x+self.nameLab.frame.size.width+4*KWidthScale, 16*KWidthScale, 36*KWidthScale, 18*KWidthScale);
    
    CGFloat size2 = [self getSpaceLabelHeight:model.flowers_describe withAttrDict:textDict withWidth: _window_width-12*KWidthScale*2];
    self.neirongLab.frame=CGRectMake(12*KWidthScale,12*KWidthScale, _window_width-12*KWidthScale*2, size2);
    
    
    NSMutableArray *resource=[NSMutableArray arrayWithArray:model.flowers_image];

    [self addSubview:self.imagebgView];
    [self.imagebgView removeAllSubviews];
    
    for (UIImageView *image in self.imageViewArrM) {
        [image removeFromSuperview];
    }
    for (int i=0; i<resource.count; i++) {
        UIImageView *images=[[UIImageView alloc]init];
        images.image=(UIImage*)resource[i];
        images.frame=CGRectMake((109*KWidthScale+8*KWidthScale)*i, 0, 109*KWidthScale, 109*KWidthScale);
        images.layer.masksToBounds=YES;
        images.layer.cornerRadius = 4*KWidthScale;
        images.contentMode=UIViewContentModeScaleAspectFill;
        [self.imagebgView addSubview:images];
        [self.imageViewArrM addObject:images];
    }
//    self.imagebgView.backgroundColor=[UIColor whiteColor];
    self.imagebgView.frame=CGRectMake(12*KWidthScale, self.neirongLab.frame.origin.y+self.neirongLab.frame.size.height+8*KWidthScale, 121*KWidthScale*3, 109*KWidthScale);
    
    
    
    self.timeLab.frame=CGRectMake(0,self.imagebgView.frame.origin.y+self.imagebgView.frame.size.height+8*KWidthScale, _window_width-12*KWidthScale, 21*KWidthScale);
    
    self.statusLab.frame=CGRectMake(12*KWidthScale,self.imagebgView.frame.origin.y+self.imagebgView.frame.size.height+8*KWidthScale, _window_width-12*KWidthScale*2, 21*KWidthScale);
    
//    self.zanBtn.frame=CGRectMake(self.touImage.frame.origin.x+self.touImage.frame.size.width+8*KWidthScale,self.timeLab.frame.origin.y+self.timeLab.frame.size.height+8*KWidthScale, 100, 18*KWidthScale);
//
//    self.qgBtn.frame=CGRectMake(_window_width-100-12*KWidthScale,self.timeLab.frame.origin.y+self.timeLab.frame.size.height+8*KWidthScale, 100, 18*KWidthScale);
    
    self.rowHeight=self.timeLab.frame.origin.y+self.timeLab.frame.size.height+12*KWidthScale;
    self.xianView.frame=CGRectMake(0, self.rowHeight-1, _window_width, 1);
}
-(void)zanAction{
    
}

@end
